//
//  FTRouter.m
//  Fitness
//
//  Created by SunZhongyuan on 2018/5/28.
//  Copyright © 2018年 SunZhongyuan. All rights reserved.
//

#import "FTRouter.h"
#import "FTCurrentViewController.h"

@interface FTRouter ()

@property (nonatomic,strong) NSDictionary * map;

@end

@implementation FTRouter


+ (instancetype)sharedInstance {
    static FTRouter *_instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self allocWithZone:NULL] init];
    });
    return _instance;
}

+ (id)allocWithZone:(struct _NSZone *)zone{
    return [self sharedInstance];
}

- (id)copyWithZone:(nullable NSZone *)zone{
    return self;
}

/*
  控制器路由注册词典
*/
- (NSDictionary *)map {
    if (!_map) {
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Router" ofType:@"plist"];
        _map = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    }
    return _map;
}


- (void)addParamWithKey:(NSString *)key value:(id)value {
    _params[key] = value;
}

- (void)clearParams {
    [_params removeAllObjects];
}

- (void)push:(NSString *)path {
    Class cls = NSClassFromString(self.map[path]);
    [kCurrentViewController.navigationController pushViewController:[cls new] animated:YES];
}


@end
